﻿using System;
using System.Collections.Generic;
using TopBuilds.Restaurant.Data;

namespace TopBuilds.Restaurant.ManagementClient
{
    public sealed class BillCollection : System.Collections.ObjectModel.ObservableCollection<Bill>
    {
        private string _condition;

        public string Condition
        {
            get { return _condition; }

            set
            {
                if (_condition != null && _condition == value)
                {
                    return;
                }

                _condition = value;

                if (Count > 0)
                {
                    base.Clear();
                }

                Bill[] list = BillObject.GetBills();
                if (list != null)
                {
                    foreach (Bill item in list)
                    {
                        Add(item);
                    }
                }
            }
        }

        /// <summary>
        /// 初始化数据, 读入全部数据记录
        /// </summary>
        public BillCollection()
        {
            Condition = null;
        }

        /// <summary>
        /// 由Bill Id 取得 Bill
        /// </summary>
        /// <param name="billId"></param>
        /// <returns></returns>
        public Bill GetBill(int billId)
        {
            foreach (Bill bill in this)
            {
                if (bill.Id == billId)
                {
                    return bill;
                }
            }

            return null;
        }
    }
}
